package Scrap;

import java.util.Scanner;

public class demo25_PermutationExample {
	public static void main(String args[]) throws Exception {
		Scanner input = new Scanner(System.in);
		System.out.print("Enter String: ");
		String input_string = input.next();

		generatePerms("", input_string);
		// System.out.println("control in main");
	}

	public static void generatePerms(String incr_str, String decr_sting) { // st
																			// is
																			// initially
																			// ""
		// System.out.println("in show pattern");
		if (decr_sting.length() <= 1) { // when the floating_sting length is
										// going to be less than/equal to a
										// single character Print the string
			System.out.println(incr_str + decr_sting); // Going to be called
														// (input_string.length)!
														// times
			// System.out.println("control here");
		} else
			for (int i = 0; i < decr_sting.length(); i++) {
				try {

					String newString = decr_sting.substring(0, i)+ decr_sting.substring(i + 1);
					
					generatePerms(incr_str + decr_sting.charAt(i), newString); // generatePerms	
																				// recursively
																				// called

				} catch (Exception e) {
					e.printStackTrace();
				}	
			}

	}
}
